package com.xin.di.uav.applet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xin.di.uav.user.order.po.OrderPO;
import com.xin.di.uav.user.order.po.Product;
import com.xin.di.uav.user.po.UserPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LTQ
 * @since 2023-12-07
 */
@Mapper
public interface CommodityMapper extends BaseMapper<Product> {



    @Select({"<script>",
            "select id, name, main_image, sale_price, supply_price, stock, \"desc\", merchant_id, created_at, updated_at,\n" +
                    "                     status, sort, rule_type, rule_info from product where id in  ",
            "       <foreach item=\"id\" collection=\"ids\" open=\"(\" separator=\",\" close=\")\">\n" +
                    "            #{id}\n" +
                    "        </foreach>" +
                    "</script>"})
    List<Product> selByIds(@Param("ids") List<String> ids);


    @Update({
            "<script>",
            "UPDATE product ",
            "<set>",
            "    <if test='stock != null'>stock = #{stock},</if>",
            "    updated_at = NOW()",

            "</set>",
            "WHERE id = #{id}",
            "</script>"
    })
    int updateStock(Product product);
}
